package com.corpcredit.webapp.action;

import java.io.Serializable;
import java.util.Date;

import org.tuckey.web.filters.urlrewrite.utils.Log;

import com.corpcredit.Constants;
import com.corpcredit.model.Fzjgxx;
import com.corpcredit.model.Jbqk;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class FzjgxxForm extends BasePage implements Serializable {
    private GenericManager<Fzjgxx, Long> fzjgxxManager;
    private Fzjgxx fzjgxx = new Fzjgxx();
    private Long id;
    private Jbqk jbqk;

    public void setFzjgxxManager(GenericManager<Fzjgxx, Long> fzjgxxManager) {
        this.fzjgxxManager = fzjgxxManager;
    }

    public Fzjgxx getFzjgxx() {
        return fzjgxx;
    }

    public void setFzjgxx(Fzjgxx fzjgxx) {
        this.fzjgxx = fzjgxx;
    }

    public void setJbqk(Jbqk jbqk)
    {
    	this.jbqk=jbqk;
    }
    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        fzjgxxManager.remove(fzjgxx.getId());
        addMessage("fzjgxx.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
    	Log.getLog(FzjgxxForm.class).debug("in edit :this.id"+this.id+"this.fzjgxx.getId()"+this.fzjgxx.getId()+" version----"+this.fzjgxx.getVersion());
        if (id != null && id != 0) {
            fzjgxx = fzjgxxManager.get(id);
        } else {
            fzjgxx = new Fzjgxx();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (fzjgxx.getId() == null || fzjgxx.getId() == 0);
        fzjgxx.setJbqk(jbqk);
        fzjgxx.setUsername(getRequest().getRemoteUser());
        fzjgxx.setOptdate(new Date());
        if(isNew)
        {
        	fzjgxx.setOperation(Constants.OPERATION_ADD);
        }else
        {
        	fzjgxx.setOperation(Constants.OPERATION_UPDATE);
        }
        
        Log.getLog(FzjgxxForm.class).debug("before save :this.id"+this.id+"this.fzjgxx.getId()"+this.fzjgxx.getId()+" version----"+this.fzjgxx.getVersion());
        fzjgxxManager.save(fzjgxx);
        Log.getLog(FzjgxxForm.class).debug("after save :this.id"+this.id+"this.fzjgxx.getId()"+this.fzjgxx.getId()+" version----"+this.fzjgxx.getVersion());
    	
        String key = (isNew) ? "fzjgxx.added" : "fzjgxx.updated";
        addMessage(key);

        if (isNew) 
        {
            return "list";
        } else 
        {
        	Log.getLog(FzjgxxForm.class).debug("this.id"+this.id+"this.fzjgxx.getId()"+this.fzjgxx.getId()+" version----"+this.fzjgxx.getVersion());
        	
        	this.id=this.fzjgxx.getId();
            return edit();
        }
    }
} 